# set PowerShell to UTF-8
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

Import-Module posh-git
$omp_config = Join-Path $PSScriptRoot ".\takuya.omp.json"
oh-my-posh init pwsh --config $omp_config | Invoke-Expression

Import-Module -Name Terminal-Icons

# PSReadLine
Set-PSReadLineOption -EditMode Emacs
Set-PSReadLineOption -BellStyle None
Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView

# Fzf
Import-Module PSFzf
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+f' -PSReadlineChordReverseHistory 'Ctrl+r'

# Env
$env:GIT_SSH = "C:\Windows\system32\OpenSSH\ssh.exe"
$env:PATH = "C:\Program Files\Git\usr\bin;"+$env:PATH   # use gnu utils
# Alias

Set-Alias alias Set-Alias
alias g git
alias grep findstr
alias p3 python
alias p3p="python -m pip"
alias python3='python'
alias new New-Item
alias -Name vim -Value nvim
alias ll ls
alias g git
alias gitback="git reset . && git checkout . && git clean -df"
alias gco="git checkout"
alias gcb="git checkout xxx"
alias grv="git remote -v"
alias grep findstr
alias tig 'C:\Program Files\Git\usr\bin\tig.exe'
alias less 'C:\Program Files\Git\usr\bin\less.exe'
alias j z
alias ofd="explorer ."
alias i="ipython --profile=ybw"
alias ca="conda activate"
alias cda="conda deactivate"
Remove-Alias md
Remove-Alias del
Remove-Alias grep
alias md "C:\Program Files\Typora\Typora.exe"
alias del="rm -Recurse -Force"
alias ahk="sudo ~/maintain/main/ahk/test.ahk"

function pon($url) {
  $env:http_proxy=$url
  $env:https_proxy=$url
}
function poff() {
  $env:http_proxy=''
  $env:https_proxy=''
}
# Utilities
function which ($command) {
  Get-Command -Name $command -ErrorAction SilentlyContinue |
    Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}
# linux中pythonpath用:分隔  win中用;分隔
function pypath() {
  $env:PYTHONPATH = $(pwd).ToString()+";"+$env:PYTHONPATH
}


$customPs1Path = "~\maintain\powershell\custom"
if (Test-Path $customPs1Path) {  
  Get-ChildItem -Path $customPs1Path -Filter *.ps1 | ForEach-Object { & $_.FullName }
} 
